from allpairspy import AllPairs

from api_py.enums.cookie import Cookie
from api_py.generate_case.template import template_case
from api_py.utils.file_sys import write_json

name = [
    {"value": "李四", "description": "姓名不为空"},
    {"value": "李四@aa", "description": "姓名存在非法字符"},
]

phone_number = [
    {"value": "15900000003", "description": "⼿机号重复"},
    {"value": "15900000000", "description": "⼿机号重复"},
    {"value": "123456", "description": "⼿机号非法"},
]

emergencyContact = [
    {"value": "张三", "description": "紧急联系⼈不为空"},
    {"value": "张三@aa", "description": "紧急联系⼈非法"},
]

emergencyPhone = [
    {"value": "15900000001", "description": "紧急联系⼈电话合法"},
    {"value": "123456", "description": "紧急联系⼈电话非法"},
]

cookie = [
    {"value": Cookie.WEIXIN_COOKIE.value, "description": "微信访客登录"},
]

body = [
    {"value": "username_is_changed", "description": "用户名被修改"},
    {"value": "李四", "description": "姓名不为空"},
    {"value": "15900000002", "description": "⼿机号合法"},
    {"value": "张三", "description": "紧急联系⼈不为空"},
    {"value": "15900000001", "description": "紧急联系⼈电话合法"},
]


def case18_user_update(api_type):
    json_result = {}
    i = 0

    parameters = [name, phone_number, emergencyContact, emergencyPhone]

    for pairs in AllPairs(parameters):
        case = template_case()
        request = case["request"]
        # 设置请求体参数
        request["body"]["name"] = pairs[0]
        request["body"]["phoneNumber"] = pairs[1]
        request["body"]["emergencyContact"] = pairs[2]
        request["body"]["emergencyPhone"] = pairs[3]

        # 设置请求头cookie
        request["headers"]["Cookie"] = cookie[0]

        json_result[i] = case
        i += 1

    # 修改用户名测试
    case = template_case()
    request = case["request"]
    # 设置请求体参数
    request["body"]["username"] = body[0]
    request["body"]["name"] = body[1]
    request["body"]["phoneNumber"] = body[2]
    request["body"]["emergencyContact"] = body[3]
    request["body"]["emergencyPhone"] = body[4]

    # 设置请求头cookie
    request["headers"]["Cookie"] = cookie[0]

    json_result[i] = case
    i += 1

    write_json(api_type.value[0]["file_name"], json_result)
